﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using DAL;

namespace _3tiers
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        DataAccess ac = new DataAccess();
        BLL.BLL business = new BLL.BLL();
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'quanLyLichDayDataSet15.tblSinhVien' table. You can move, or remove it, as needed.
            //this.tblSinhVienTableAdapter.Fill(this.quanLyLichDayDataSet15.tblSinhVien);
            // TODO: This line of code loads data into the 'quanLyLichDayDataSet2.tblBoMon' table. You can move, or remove it, as needed.
            //this.tblBoMonTableAdapter.Fill(this.quanLyLichDayDataSet2.tblBoMon);
            // TODO: This line of code loads data into the 'quanLyLichDayDataSet4.tblBoMon' table. You can move, or remove it, as needed.
            //this.tblBoMonTableAdapter.Fill(this.quanLyLichDayDataSet4.tblBoMon);
            // TODO: This line of code loads data into the 'quanLyLichDayDataSet3.tblKhoa' table. You can move, or remove it, as needed.
            //this.tblKhoaTableAdapter.Fill(this.quanLyLichDayDataSet3.tblKhoa);
            tabPage1_Click(sender, e);
            tabPage2_Click(sender, e);
            tabPage3_Click(sender, e);
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {
            string sql = "select gv.IDGiaoVien,TenGiaoVien,HocVi,bm.TenBoMon,NgaySinh,SDT,Email from tblGiaoVien gv,tblBoMon bm where gv.IDBoMon=bm.IDBoMon";            
            dataGridView1.DataSource = business.ShowData(sql);
        }

        private void btInsertGV1_Click(object sender, EventArgs e)
        {
                        
        }

        private void tabPage2_Click(object sender, EventArgs e)
        {
            try
            {
                tabPage2.Refresh();
                //string sql = "select * from tblBoMon";
                string sql = "select TenMon,TenBoMon,SoTinChi from tblBoMon bm,tblMon m where bm.IDBoMon=m.IDBoMon";            
                dataGridView2.DataSource = business.ShowData(sql);
                dataGridView2.Show();                
            }
            catch {  }          
        }

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btUpdateGV_Click(object sender, EventArgs e)
        {
            Form3DeleteGiaoVien dt = new Form3DeleteGiaoVien();
            dt.Show();            
        }

        private void btDeleteGV_Click(object sender, EventArgs e)
        {
            
        }

        private void btThemMon_Click(object sender, EventArgs e)
        {
            Form4ThemMon dt = new Form4ThemMon();
            dt.Show();
        }

        private void btSuaMon_Click(object sender, EventArgs e)
        {
            Form4SuaMon dt = new Form4SuaMon();
            dt.Show();
        }

        private void btXoaMon_Click(object sender, EventArgs e)
        {
            Form4XoaMon dt = new Form4XoaMon();
            dt.Show();
        }

        private void btThemBoMon_Click(object sender, EventArgs e)
        {
            Form_ThemBoMon dt = new Form_ThemBoMon();
            dt.Show();
        }

        private void btSuaBoMon_Click(object sender, EventArgs e)
        {
            Form_SuaBoMon dt = new Form_SuaBoMon();
            dt.Show();
        }

        private void btXoaBoMon_Click(object sender, EventArgs e)
        {
            Form_XoaBoMon dt = new Form_XoaBoMon();
            dt.Show();
        }        

        private void btThemSV_Click(object sender, EventArgs e)
        {
            tab3_Form_ThemSV dt = new tab3_Form_ThemSV();
            dt.Show();
        }

        private void btXemLichDay_Click(object sender, EventArgs e)
        {
            tab1_Form_XemLichDay dt = new tab1_Form_XemLichDay();
            dt.Show();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                btThemBoMon.Hide();
                btSuaBoMon.Hide();
                btXoaBoMon.Hide();
                btThemMon.Show();
                btSuaMon.Show();
                btXoaMon.Show();
                
            }
            else
            {
                btThemMon.Hide();
                btSuaMon.Hide();
                btXoaMon.Hide();
                btThemBoMon.Show();
                btSuaBoMon.Show();
                btXoaBoMon.Show();             
            }
        }

        private void radioButton1_Click(object sender, EventArgs e)
        {
            
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void btChinhSuaGV_Click(object sender, EventArgs e)
        {
            form_ThemSuaXoaGiaoVien dt = new form_ThemSuaXoaGiaoVien();
            dt.Show();
        }

        private void tabPage3_Click(object sender, EventArgs e)
        {
            //string sql3 = "select khoa.TenKhoa as Khoa,gv.TenGiaoVien as Ten_Giao_Vien,nh.IDNhom as Nhom,m.TenMon,ThuNgay,TietBatDau,TietKetThuc,Phong from tblLichDay ld,tblGiaoVien gv,tblNhom nh,tblMon m,tblKhoa khoa where ld.IDGiaoVien=gv.IDGiaoVien and ld.IDMon=m.IDMon and khoa.IDKhoa=gv.IDKhoa and ld.IDNhom=nh.IDNhom";
            string sql3 = "stSelectAllLichDayGiaoVien";
            dataGridView3.DataSource = business.ShowData(sql3);
        }

        private void btThemLichDay_Click(object sender, EventArgs e)
        {
            form_XepLichDay dt = new form_XepLichDay();
            dt.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tab1_Form_XemLichDay dt = new tab1_Form_XemLichDay();
            dt.Show();
        }        

        
        /*
        //them
        private void tbInsert_Click(object sender, EventArgs e)
        {
            try
            {
                business.Insert(tbMaSV.Text, tbTenSV.Text);
            }
            catch
            {
                MessageBox.Show("Sinh vien nay da bi trung", "Thong bao");
            }
            Form1_Load(sender, e);
        }
        //sua
        private void btUpDate_Click(object sender, EventArgs e)
        {
            business.UpDate(tbMaSV.Text, tbTenSV.Text);
            Form1_Load(sender, e);
        }
        //xoa
        private void btDelete_Click(object sender, EventArgs e)
        {
            business.Delete(tbMaSV.Text);
            Form1_Load(sender, e);
        }
        int dong;
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dong = e.RowIndex;
            try
            {
                tbMaSV.Text = dataGridView1.Rows[dong].Cells[0].Value.ToString();
                tbTenSV.Text = dataGridView1.Rows[dong].Cells[1].Value.ToString();
            }
            catch
            {
                MessageBox.Show("khong co dong nay", "Thong bao");
            }
        }

        private void tbSearch_TextChanged(object sender, EventArgs e)
        {

        }

        private void btSearch_Click(object sender, EventArgs e)
        {
            if (tbSearch.Text.Length == 0) Form1_Load(sender, e);
            else
            {
                string sql = "select * from tblSinhVien where MaSV='" + tbSearch.Text + "'";
                if (rbMaSV.Checked) dataGridView1.DataSource = ac.GetTable(sql);
                else
                {
                    sql = "select * from tblSinhVien where TenSV like N'%" + tbSearch.Text + "%'";
                    if (rbTenSV.Checked) dataGridView1.DataSource = ac.GetTable(sql);

                }
            }
        }*/
    }
}
